package com.example.runningman.user;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.runningman.MainActivity;
import com.example.runningman.R;
import com.example.runningman.util.SPUtil;

public class AchieActivity extends AppCompatActivity implements View.OnClickListener{
    ImageButton imageButton;
    ImageView imageView1;
    ImageView imageView2;
    ImageView imageView3;
    ImageView imageView4;
    ImageView imageView5;
    ImageView imageView6;
    ImageView imageView7;
    ImageView imageView8;
    ImageView imageView9;
    ImageView imageView0;
    TextView textView1;
    TextView textView2;
    TextView textView3;
    TextView textView4;
    TextView textView5;
    TextView textView6;
    TextView textView7;
    TextView textView8;
    TextView textView9;
    TextView textView0;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_achie);
        imageButton = findViewById(R.id.back3);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(AchieActivity.this, MainActivity.class);
                startActivity(intent);
            }
        });
        init();
    }
    @SuppressLint("SetTextI18n")
    public void init(){
        imageView1= findViewById(R.id.achi_pic);
        imageView2= findViewById(R.id.achi_pic2);
        imageView3= findViewById(R.id.achi_pic3);
        imageView4= findViewById(R.id.achi_pic4);
        imageView5= findViewById(R.id.achi_pic5);
        imageView6= findViewById(R.id.achi_pic6);
        imageView7= findViewById(R.id.achi_pic7);
        imageView8= findViewById(R.id.achi_pic8);
        imageView9= findViewById(R.id.achi_pic9);
        imageView0= findViewById(R.id.achi_pic0);
        textView1= findViewById(R.id.achi_text);
        textView2= findViewById(R.id.achi_text2);
        textView3= findViewById(R.id.achi_text3);
        textView4= findViewById(R.id.achi_text4);
        textView5= findViewById(R.id.achi_text5);
        textView6= findViewById(R.id.achi_text6);
        textView7= findViewById(R.id.achi_text7);
        textView8= findViewById(R.id.achi_text8);
        textView9= findViewById(R.id.achi_text9);
        textView0= findViewById(R.id.achi_text0);
        imageView1.setOnClickListener(this);
        imageView2.setOnClickListener(this);
        imageView3.setOnClickListener(this);
        imageView4.setOnClickListener(this);
        imageView5.setOnClickListener(this);
        imageView6.setOnClickListener(this);
        imageView7.setOnClickListener(this);
        imageView8.setOnClickListener(this);
        imageView9.setOnClickListener(this);
        imageView0.setOnClickListener(this);
        count=SPUtil.getInstance(AchieActivity.this).getLong("count", 0);
        day=SPUtil.getInstance(AchieActivity.this).getInt("day",0);
        total=SPUtil.getInstance(AchieActivity.this).getLong("total", 0);
         textView1.setText(count+"/1000m");
         textView2.setText(count+"/5000m");
         textView3.setText(count+"/10000m");
         textView4.setText(count+"/50000m");
         textView5.setText(day+"/1");
         textView6.setText(day+"/3");
         textView7.setText(day+"/15");
         textView8.setText(day+"/30");
         textView9.setText(total+"/5000");
         textView0.setText(total+"/10w");
         if(count>=1000){
             Glide.with(AchieActivity.this).load(R.drawable.a1ed).into(imageView1);
         }if(count>=5000){
             Glide.with(AchieActivity.this).load(R.drawable.a3ed).into(imageView2);
        }if(count>=10000){
             Glide.with(AchieActivity.this).load(R.drawable.a4ed).into(imageView3);
        }if(count>=1000000){
             Glide.with(AchieActivity.this).load(R.drawable.a5ed).into(imageView4);
        }
        if(day>=1){
            Glide.with(AchieActivity.this).load(R.drawable.a2ed).into(imageView5);
        }if(day>=3){
            Glide.with(AchieActivity.this).load(R.drawable.a2ed1).into(imageView6);
        }if(day>=15){
            Glide.with(AchieActivity.this).load(R.drawable.a2ed2).into(imageView7);
        }if(day>=30) {
            Glide.with(AchieActivity.this).load(R.drawable.a2ed3).into(imageView8);
        }
        if(total>=5000){
            Glide.with(AchieActivity.this).load(R.drawable.a6ed).into(imageView9);
        }
        if(total>=100000){
            Glide.with(AchieActivity.this).load(R.drawable.a6ed2).into(imageView0);
        }
    }
    long count;
    int day;
    long total;
    @Override
    public void onClick(View v) {
        Dialog dia;
        dia = new Dialog(AchieActivity.this, R.style.edit_AlertDialog_style);
        dia.setContentView(R.layout.activity_start_dialog);
        ImageView imageView = (ImageView) dia.findViewById(R.id.start_img);
         switch (v.getId()){
             case R.id.achi_pic:
                 if(count>=1000){
                     Glide.with(AchieActivity.this).load(R.drawable.a1ed).into(imageView);
                 }else {
                     Glide.with(AchieActivity.this).load(R.drawable.a1).into(imageView);
                 }

                 break;
             case R.id.achi_pic2:
                 if(count>=5000){
                     Glide.with(AchieActivity.this).load(R.drawable.a3ed).into(imageView2);
                 }
                 else  Glide.with(AchieActivity.this).load(R.drawable.a3).into(imageView);
                 break;
             case R.id.achi_pic3:
                 if(count>=10000){
                     Glide.with(AchieActivity.this).load(R.drawable.a4ed).into(imageView3);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a4).into(imageView);
                 break;
             case R.id.achi_pic4:
                 if(count>=1000000){
                     Glide.with(AchieActivity.this).load(R.drawable.a5ed).into(imageView4);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a5).into(imageView);
                 break;
             case R.id.achi_pic5:
                 if(day>=1){
                     Glide.with(AchieActivity.this).load(R.drawable.a2ed).into(imageView5);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a2).into(imageView);
                 break;
             case R.id.achi_pic6:
                 if(day>=3){
                     Glide.with(AchieActivity.this).load(R.drawable.a2ed1).into(imageView6);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a21).into(imageView);
                 break;
             case R.id.achi_pic7:
                 if(day>=15){
                     Glide.with(AchieActivity.this).load(R.drawable.a2ed2).into(imageView7);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a22).into(imageView);
                 break;
             case R.id.achi_pic8:
                 if(day>=30) {
                     Glide.with(AchieActivity.this).load(R.drawable.a2ed3).into(imageView8);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a23).into(imageView);
                 break;
             case R.id.achi_pic9:
             case R.id.achi_pic0:
                 if(total>=5000&&total<100000){
                     Glide.with(AchieActivity.this).load(R.drawable.a6ed).into(imageView9);
                 }
                else if(total>=100000){
                     Glide.with(AchieActivity.this).load(R.drawable.a6ed2).into(imageView0);
                 }
                 else Glide.with(AchieActivity.this).load(R.drawable.a6).into(imageView);

                 break;

         }

        //选择true的话点击其他地方可以使dialog消失，为false的话不会消失
        dia.setCanceledOnTouchOutside(true); // Sets whether this dialog is
        Window w = dia.getWindow();
        WindowManager.LayoutParams lp = w.getAttributes();
        lp.x = 0;
        lp.y = 40;
        dia.onWindowAttributesChanged(lp);
        dia.show();
        imageView.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        dia.dismiss();
                    }
                });
    }
}
